/*
 * Crawler.cpp
 *
 *  Created on: Jul 21, 2012
 *      Author: Kris Clark
 */

#include <boost/filesystem.hpp>
#include <boost/algorithm/string/find.hpp>
#include <fstream>
#include <istream>
#include "Crawler.h"

using namespace std;
using namespace boost::filesystem;

void Crawler::startCrawl()
{
	string *files;											// This will hold all of the paths
	int fileCount = getFilePath();							// Create a temp database of all the files on
															// this HDD
	files = new string[fileCount];							// Adjust the array for the number of files

	ifstream tempFile("./database.tmp");					// Open our file database
	string line;											// This will hold each line of the db
	vector<std::string> user_vec;

	while(getline(tempFile, line)) {
		user_vec.push_back(line);
	}

	size_t line_count = user_vec.size();
	for(size_t i=0; i < line_count; ++i)
	{
		files[i] = user_vec[i];
	}

	cout << files[1900] << endl;
}

int Crawler::getFilePath()
{
	int fileCount;											// How many file do we have?

	getFiles();												// Output all the files on the HDD database.tmp
	fileCount = getFileCount();								// Count how many files we have

	return fileCount;
}

void Crawler::getFiles()
{
	char record[1000];										// Declaration of record
	sprintf(record,"/usr/bin/locate * / > database.tmp");	// Get the list of files
	system(record);
}

int Crawler::getFileCount()
{
	int fileCount = 0;
	string line;
	ifstream myfile("./database.tmp");

	while(getline(myfile, line))
	{
		fileCount++;
	}

	return fileCount;
}

Crawler::Crawler() {
	// TODO Auto-generated constructor stub

}

Crawler::~Crawler() {
	// TODO Auto-generated destructor stub
}
